/**
Copyright 2011 Patrick Devaney

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <iostream>
#include <string.h>
#include <math.h>
#define _USE_MATH_DEFINES
using namespace std;

/*
File purpose:
main.cpp includes this, and this function seamlessly performs
I/O and calculations.
*/

// 3.14159
long double pi = M_PI;

int area(void) {
// As I've done before, I use i as a loop so the program doesn't crash if
// one enters something not on the menu or the feature in question isn't implemented
int i;
// This takes the input of which option the user chooses
string input;
i = 0;
while(i < 1) {
cout << "Do you want to calculate:" << endl;
cout << "1 - The area of a circle" << endl << "2 - The area of an ellipse" << endl
<< "3 - The area of a square" << endl << "4 - The area of a rectangle" << endl
<< "5 - The area of a parallelogram" << endl << "6 - The area of a trapezoid" << endl
<< "7 - The area of a triangle" << endl;
cin >> input;
if(input == "1") {
cout << "Do you want to calculate the area of a circle using:" << endl
<< "a - the radius" << endl << "b - the diameter" << endl;
string a;
cin >> a;
bool b;
	if(a == "a") {
	b = false;
	}
	else if(a == "b") {
	b = true;
	}
cout << "What is the ";
	if(b == false) {
	cout << "radius";
	}
	else {
	cout << "diameter";
	}
cout << " of the circle?" << endl;
long double radius;
cin >> radius;
	if(b == true) {
	radius = radius / 2;
	}
long double area ;
area = radius * radius;
area = area * pi;
cout << "The area of the circle is:" << endl << area << endl;
i++;
}
else if(input == "2") {
long double area, r1, r2;
cout << "What's the first radius?" << endl;
cin >> r1;
cout << "What's the second radius?" << endl;
cin >> r2;
area = r1 * r2;
area = area * pi;
cout << "The area of the ellipse is:" << endl << area << endl;
}
else if(input == "3") {
cout << "What is the length of one side?" << endl;
long double side;
cin >> side;
side = side * side;
cout << "The area of the square is:" << endl << side << endl;
i++;
}
else if(input == "4") {
cout << "What is the length of the rectangle?" << endl;
long double length, width, area;
cin >> length;
cout << "What is the width of the rectangle?" << endl;
cin >> width;
	if(length == width) {
	cout << "That's a square! Use option 3 next time, and save yourself the effort of " << endl
	<< "entering the same number twice!" << endl;
	}
area = length * width;
cout << "The area of the rectangle is:" << endl << area << endl;
i++;
}

else if(input == "5") {
long double area, base, height;
cout << "What is the base of the parallelogram?" << endl;
cin >> base;
cout << "What is the height of the parallelogram?" << endl;
cin >> height;
area = base * height;
cout << "The area of the parallelogram is:" << endl << area << endl;
i++;
}

else if(input == "6") {
long double b1, b2, h, area;
cout << "What's the first base of the trapezoid?" << endl;
cin >> b1;
cout << "What's the second base of the trapezoid?" << endl;
cin >> b2;
cout << "What's the height of the trapezoid?";
cin >> h;
h = h / 2;
area = b1 + b2;
area = h * area;
cout << "The area of the trapezoid is:" << endl << area << endl;
i++;
}

else if(input == "7") {
long double b, h, area;
cout << "What's the base of the triangle?" << endl;
cin >> b;
cout << "What's the height of the triangle?" << endl;
cin >> h;
area = b * h;
area = area / 2;
cout << "The area of the triangle is:" << endl << area << endl;
i++;
}

// End of the while
}
// End of the function
}